package org.dromara.system.business.review.service.impl;

import jakarta.annotation.Resource;
import org.dromara.system.business.review.entity.ReviewRecord;
import org.dromara.system.business.review.dao.ReviewRecordDao;
import org.dromara.system.business.review.service.ReviewRecordService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

/**
 * (ReviewRecord)表服务实现类
 *
 * @author makejava
 * @since 2025-02-07 16:38:54
 */
@Service("reviewRecordService")
public class ReviewRecordServiceImpl implements ReviewRecordService {
    @Resource
    private ReviewRecordDao reviewRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ReviewRecord queryById(Long id) {
        return this.reviewRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param reviewRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ReviewRecord> queryByPage(ReviewRecord reviewRecord, PageRequest pageRequest) {
        long total = this.reviewRecordDao.count(reviewRecord);
        return new PageImpl<>(this.reviewRecordDao.queryAllByLimit(reviewRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param reviewRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ReviewRecord insert(ReviewRecord reviewRecord) {
        this.reviewRecordDao.insert(reviewRecord);
        return reviewRecord;
    }

    /**
     * 修改数据
     *
     * @param reviewRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ReviewRecord update(ReviewRecord reviewRecord) {
        this.reviewRecordDao.update(reviewRecord);
        return this.queryById(reviewRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.reviewRecordDao.deleteById(id) > 0;
    }
}
